package com.k12.user.controller;

import com.k12.user.model.entity.SysUserRole;
import com.k12.user.service.SysUserRoleService;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import javax.annotation.Resource;

/**
 * 用户和角色关联表(SysUserRole)表控制层
 *
 * @author makejava
 * @since 2025-07-28 20:53:08
 */
@RestController
@RequestMapping("sysUserRole")
public class SysUserRoleController {
    /**
     * 服务对象
     */
    @Resource
    private SysUserRoleService sysUserRoleService;

    /**
     * 分页查询
     *
     * @param sysUserRole 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping("getAllUserRole")
    public List<SysUserRole> queryByPage(SysUserRole sysUserRole) {
        return this.sysUserRoleService.queryByPage(sysUserRole);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getOneUserRole/{id}")
    public SysUserRole queryById(@PathVariable("id") Long id) {
        return this.sysUserRoleService.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param sysUserRole 实体
     * @return 新增结果
     */
    @PostMapping("insertUserRole")
    public SysUserRole add(SysUserRole sysUserRole) {
        return this.sysUserRoleService.insert(sysUserRole);
    }


    /**
     * 新增数据
     *
     * @param sysUserRole 实体
     * @return 新增结果
     */
    @PostMapping("addUserRole")
    public void addUserRole(List<SysUserRole> sysUserRole) {
        this.sysUserRoleService.addUserRole(sysUserRole);
    }

    /**
     * 编辑数据
     *
     * @param sysUserRole 实体
     * @return 编辑结果
     */
    @PostMapping("updateUserRole")
    public SysUserRole edit(SysUserRole sysUserRole) {
        return this.sysUserRoleService.update(sysUserRole);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("deleteUserRole")
    public Boolean deleteById(Long id) {
        return this.sysUserRoleService.deleteById(id);
    }



    @GetMapping("deleteUserRoleByTenantId")
    public void deleteUserRoleByTenantId(@RequestParam("userId")Long id,@RequestParam("tenantId")String tenantId) {
        this.sysUserRoleService.deleteUserRoleByTenantId(id,tenantId);
    }

    @GetMapping("getRoleIds")
    public List<Long> getRoleIds(@RequestParam("userId")String userId,@RequestParam("tenantId")String tenantId) {
        return this.sysUserRoleService.getRoleIds(userId,tenantId);
    }

    @PostMapping("saveSysUserRole")
    public int saveSysUserRole(List<SysUserRole> list) {
        return this.sysUserRoleService.saveSysUserRole(list);
    }


    @PostMapping("user/deleteAuthUser")
    public int deleteAuthUser(SysUserRole userRole){
        return this.sysUserRoleService.deleteAuthUser(userRole);
    }


}

